package cn.breeze.org.service.impl;

import cn.breeze.basic.utils.PageList;
import cn.breeze.org.domain.Department;
import cn.breeze.org.mapper.DepartmentMapper;
import cn.breeze.org.query.DepartmentQuery;
import cn.breeze.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
// 只读事务
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;


    /**
    * @Title: loadAll
    * @Description: TODO
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/6/21 18:39
    * @Parameters: []
    * @Return java.util.List<cn.breeze.org.domain.Department>
    */
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    /** 
    * @Title: loadById
    * @Description: TODO
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/6/21 18:47  
    * @Parameters: [id]
    * @Return cn.breeze.org.domain.Department
    */
    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    /** 
    * @Title: remove
    * @Description: TODO
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/6/21 18:46  
    * @Parameters: [id]
    * @Return 
    */
    @Override
    @Transactional
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    /**
    * @Title: save
    * @Description: TODO
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/6/21 18:39
    * @Parameters: [department]
    * @Return void
    */
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    /** 
    * @Title: update
    * @Description: TODO
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/6/21 18:38  
    * @Parameters: [department]
    * @Return void
    */
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /** 
    * @Title: queryData
    * @Description: TODO
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/6/21 18:36  
    * @Parameters: [departmentQuery]
    * @Return cn.breeze.basic.utils.PageList<cn.breeze.org.domain.Department>
    */
    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {

        // 1.查询分页总条数
        Integer total = departmentMapper.queryCount(departmentQuery);
        // 2.查询当前页数据
        List<Department> rows = departmentMapper.queryData(departmentQuery);

        return new PageList<>(total, rows);
    }
}
